Walkthrough 10-5: Handle errors at the processor level
In this walkthrough, you work with the Scatter-Gather in getAllAirlineFlights so that it correctly returns results when one but not all airlines have flights. You will:
· Wrap the Flow Reference in each branch of a Scatter-Gather in a Try scope.
· Use an On Error Continue scope in each Try scope error handler to provide a valid response so flow execution can continue.
Starting file
If you did not complete the previous walkthrough, you can get a starting file here. This file is also located in the solutions folder of the student files ZIP located in the Course Resources.
Debug the application when a Scatter-Gather branch has an error
1. Return to implementation.xml in Anypoint Studio.
2. Debug the project and proceed through any errors in the workspace.
3. In Advanced REST Client, make another request to http://localhost:8081/flights?code=PDX.
4. Return to the Mule Debugger and step through the application until you see a routing exception.
5. Step through the rest of the application.
6. Return to Advanced REST client, you should get the 500 Server Error that there were exceptions in routes 0 and 2.
7. Return to Anypoint Studio and switch to the Mule Design perspective.
Place each Flow Reference in the Scatter-Gather in a Try scope
8. Locate getAllAirlineFlights.
9. Drag a Try scope from the Mule Palette and drop it in the Scatter-Gather before the getAmericanFlights Flow Reference.
10. Drag the getAmericanFlights Flow Reference into the Try scope.
11. Add Try scopes to the other two routes of the Scatter-Gather.
12. Move the getUnitedFlights Flow Reference into one of the Try scopes and the getDeltaFlights Flow Reference into the other.
Add an error handler to each branch that passes through the error message
13. Expand the error handling section of the first Try scope.
14. Add an On Error Continue scope and set the types of errors it handles to ANY.
15. Repeat these steps to add the same error handler to the two other Try scopes.
Debug the application
16. Save the file to redeploy the project.
17. In Advanced REST Client, make another request to http://localhost:8081/flights?code=PDX.
18. In the Mule Debugger, step through the application until you are at the Logger after the Scatter-Gather in getAllAirlineFlights.
19. Expand Payload; you should see three flights (from United) and two error messages.
20. Step through the rest of the application.
21. Return to Advanced REST Client; you should see United flights and error messages.
Modify each error handler to set the payload to an empty array
22. Return to Anypoint Studio and switch to the Mule Design perspective.
23. In getAllAirlineFlights, add a Transform Message component to one of the On Error Continue scopes.
24. Set the display name to [].
25. In the Transform Message properties view, set the payload to an empty array.
26. Repeat the steps to add the same Transform Message component to the two other error handlers.
Debug the application
27. Save the file to redeploy the project.
28. In Advanced REST Client, make another request to http://localhost:8081/flights?code=PDX.
29. In the Mule Debugger, step through the application until you are at the Logger after the Scatter-Gather in getAllAirlineFlights.
30. Expand Payload; you should now see the three flights and no error messages.
31. Step through the rest of the application.
32. Return to Advanced REST Client; you should now only see the three flights.
33. Return to Anypoint Studio and switch to the Mule Design perspective.
34. Stop the project.